import { arrayGroup } from "@/utils/smallTool";

const statusConfig = {
    '0': '维护中',
    '1': '已开通',
    '2': '未开通'
};
const accountEntryConfig = {
    '0': '不支持',
    '1': '全部数据',
    '2': '近三年数据',
    '3': '近一年数据'
}
const calculatorConfig = {
    '0': '不支持',
    '1': '官网获取',
    '2': '公式计算'
};
const supportConfig = {
    '0': '不支持',
    '1': '支持'
};
const staticsticsConfig = {
    '0': '按年统计',
    '1': '次统计'
};
const suportConfig = [
    { name: '不支持', value: '0' },
    { name: '官网链接', value: '1' },
    { name: '查悦链接', value: '2' },
]
const registeArr = [{ value: '0', name: '不支持' }, { value: '1', name: '官网连接' }, { value: '2', name: '查悦链接' }];
const statisticsArr = [{ value: '1', name: '全部数据' }, { value: '2', name: '近一年数据' },
{ value: '3', name: '近二年数据' }, { value: '4', name: '近三年数据' }];
const calcArr = [{ value: '0', name: '不支持' }, { value: '1', name: '官网获取' }, { value: '2', name: '公式计算' }];
const insuranceList = [
    { name: '不支持', value: '00:不支持' },
    { name: '养老', value: '01:养老' },
    { name: '失业', value: '02:失业' },
    { name: '医疗', value: '03:医疗' },
    { name: '工伤', value: '04:工伤' },
    { name: '生育', value: '05:生育' },
    { name: '大病险', value: '06:大病险' },
    { name: '基础五险', value: '07:基础五险' },
    { name: '六险', value: '08:六险' },
];
const transArrByObj = (obj) => {
    return Object.keys(obj).map((key) => {
        return {
            name: obj[key],
            value: key
        }
    })
}
const getDataByKeys = (list, keys) => {
    let arr = [];
    list.forEach((item) => {
        if (~keys.indexOf(item.name)) {
            arr.push(item.value);
        }
    })
    return arr;
}
const getSecuritySearchInputConfig = (cityList) => [
    {
        type: 'select',
        placeholder: '请选择城市',
        name: 'cityCode',
        label: '城市',
        nameFiled: 'cityName',
        valueFiled: 'cityCode',
        optionData: cityList
    },
    {
        type: 'select',
        placeholder: '请选择城市状态',
        optionData: [{ value: '0', name: '维护中' }, { value: '1', name: '已开通' }, { value: '2', name: '未开通' }],
        name: 'status',
        label: '城市状态',
        selectProps: {
            allowClear: true,
        }
    },
    {
        type: 'select',
        placeholder: '请选择激活注册',
        optionData: registeArr,
        name: 'activationRegisteredLink',
        label: '激活注册',
        selectProps: {
            allowClear: true,
        }
    },
    {
        type: 'select',
        placeholder: '请选择忘记密码',
        optionData: registeArr,
        name: 'forgetPasswordLink',
        label: '忘记密码',
        selectProps: {
            allowClear: true,
        }
    },
    {
        type: 'select',
        placeholder: '请选择入账明细数据统计',
        optionData: statisticsArr,
        name: 'accountEntryDetail',
        label: '入账明细数据统计',
        selectProps: {
            allowClear: true,
        }
    },

    {
        type: 'select',
        placeholder: '请选择社保账户（养老）',
        optionData: calcArr,
        name: 'pension',
        label: '社保账户（养老）',
        selectProps: {
            allowClear: true,
        }
    },
    {
        type: 'select',
        placeholder: '请选择医保账户（医疗）',
        optionData: calcArr,
        name: 'medical',
        label: '医保账户（医疗）',
        selectProps: {
            allowClear: true,
        }
    }, {
        type: 'select',
        placeholder: '请选择社保账户（医疗划入账）',
        optionData: calcArr,
        name: 'medicalDebit',
        label: '社保账户（医疗划入账）',
        selectProps: {
            allowClear: true,
        }
    },
    {
        type: 'select',
        placeholder: '请选择医疗支出（是否支持）',
        optionData: [{ value: '0', name: '不支持' }, { value: '1', name: '支持' }],
        name: 'medicalExpenditure',
        label: '医疗支出（是否支持）',
        selectProps: {
            allowClear: true,
        }
    },
    {
        type: 'select',
        placeholder: '请选择医疗支出（统计类型）',
        optionData: [{ value: '0', name: '按年统计' }, { value: '1', name: '按月统计' }],
        name: 'statisticsType',
        label: '医疗支出（统计类型）',
        selectProps: {
            allowClear: true,
        }
    },
    {
        type: 'select',
        placeholder: '请选择医疗支出（统计数据）',
        optionData: statisticsArr,
        name: 'statisticsData',
        label: '医疗支出（统计数据）',
        selectProps: {
            allowClear: true,
        }
    },
];
const getEditInputConfig = (record) => {
    return [
        {
            type: 'input',
            placeholder: '请选择',
            name: 'cityCode',
            hidden: true,
            initialValue: record.cityCode,
            label: '城市',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'cityName',
            nameFiled: 'cityName',
            valueFiled: 'cityCode',
            require: true,
            disabled: record.cityName ? true : false,
            initialValue: record.cityName,
            optionList: {
                list: record.cityList
            },
            label: '城市',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'status',
            decorator: true,
            initialValue: String(record.status || '0'),
            optionList: {
                list: transArrByObj(statusConfig)
            },
            label: '城市状态',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'activationRegisteredLink',
            initialValue: String(record.activationRegisteredLink || '0'),
            decorator: true,
            optionList: {
                list: suportConfig
            },
            label: '激活注册',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'forgetPasswordLink',
            decorator: true,
            initialValue: String(record.forgetPasswordLink || '0'),
            optionList: {
                list: suportConfig
            },
            label: '忘记密码',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'accountEntryDetail',
            decorator: true,
            initialValue: String(record.accountEntryDetail || '1'),
            optionList: {
                list: statisticsArr
            },
            label: '入账明细数据统计',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'pension',
            decorator: true,
            initialValue: String(record.pension || '0'),
            optionList: {
                list: transArrByObj(calculatorConfig)
            },
            label: '社保帐户（养老帐户）',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'medical',
            decorator: true,
            initialValue: String(record.medical || '0'),
            optionList: {
                list: transArrByObj(calculatorConfig)
            },
            label: '社保帐户（医疗帐户）',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'medicalDebit',
            decorator: true,
            initialValue: String(record.medicalDebit || '0'),
            optionList: {
                list: transArrByObj(calculatorConfig)
            },
            label: '医疗划入帐',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'medicalExpenditure',
            decorator: true,
            initialValue: String(record.medicalExpenditure || '0'),
            optionList: {
                list: transArrByObj(supportConfig)
            },
            label: '医疗支出',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'statisticsType',
            decorator: true,
            initialValue: String(record.statisticsType || '0'),
            optionList: {
                list: transArrByObj(staticsticsConfig)
            },
            label: '医疗支出（统计类型）',
        },
        {
            type: 'select',
            placeholder: '请选择',
            name: 'statisticsData',
            initialValue: String(record.statisticsData || 1),
            decorator: true,
            optionList: {
                list: statisticsArr
            },
            label: '医疗支出（统计数据）',
        },
        {
            type: 'checkbox',
            name: 'insurance',
            decorator: true,
            initialValue: record.insurance && getDataByKeys(insuranceList, record.insurance.split(',')),
            optionList: {
                list: insuranceList,
            },
            label: '支持险种',
        },
    ]
};
const getTableConfig = (OptionNode) => {
    const registerConfig = {
        '0': '不支持', '1': '官网链接', '2': '查悦链接'
    }
    return [
        {
            title: '城市编码',
            dataIndex: 'cityCode',
        },
        {
            title: '城市名称',
            dataIndex: 'cityName',
        },
        {
            title: '状态',
            dataIndex: 'status',
            render: (text) => (statusConfig[text])
        },
        {
            title: '激活注册',
            dataIndex: 'activationRegisteredLink',
            width: '10%',
            render: (text) => (registerConfig[text])
        },
        {
            title: '忘记密码',
            dataIndex: 'forgetPasswordLink',
            render: (text) => (registerConfig[text])
        },
        {
            title: '支持险种',
            dataIndex: 'insurance'
        },
        {
            title: '入账明细',
            dataIndex: 'accountEntryDetail',
            render: (text) => (accountEntryConfig[text])
        },
        {
            title: '社保帐户',
            dataIndex: 'shebao',
            children: [
                {
                    title: '养老',
                    dataIndex: 'pension',
                    render: (text) => (calculatorConfig[text])
                },
                {
                    title: '医疗',
                    dataIndex: 'medical',
                    render: (text) => (calculatorConfig[text])
                },
                {
                    title: '医疗划入账',
                    dataIndex: 'medicalDebit',
                    render: (text) => (calculatorConfig[text])
                },
            ],
        },
        {
            title: '医疗支出',
            dataIndex: 'gongjj',
            children: [
                {
                    title: '是否支持',
                    dataIndex: 'medicalExpenditure',
                    render: (text) => (supportConfig[text])
                },
                {
                    title: '统计类型',
                    dataIndex: 'statisticsType',
                    render: (text) => (staticsticsConfig[text])
                },
                {
                    title: '统计数据',
                    dataIndex: 'statisticsData',
                    render: (text) => (accountEntryConfig[text])
                },
            ],
        },
        {
            title: '操作',
            dataIndex: 'note',
            render: (text, record) => <OptionNode record={record}></OptionNode>
        },
    ];
}
export default {
    getEditInputConfig,
    getSecuritySearchInputConfig,
    getTableConfig
}